package com.libweb.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.libweb.model.dao.BoardDao;
import com.libweb.model.dao.MemberDao;
import com.libweb.model.dto.Member;

@WebServlet("/member/delete.action")
public class MemberDeleteServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		//1. 요청 데이터 읽기 (아이디)
		String memberId = req.getParameter("memberid");
		String loginuser = req.getParameter("loginuser");
		//String loginuser = req.getParameter("loginuser");
		
//		if (memberId == null || memberId.length() == 0) {
//			resp.sendRedirect("list.action");
//			return;
//		}
//		
		//2. 데이터 처리 (db에서 데이터 변경)
		MemberDao dao = new MemberDao();
		dao.deleteMember(memberId);
		
		//3. 목록으로 이동
		if(loginuser.equals("admin")) {
			resp.sendRedirect("/libweb/member/list.action");
		}else {
			req.getSession().removeAttribute("loginuser");
			resp.sendRedirect("/libweb/home.action");
		}
	
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		doGet(req, resp);
	}
	
}




